package tests;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import cruncher.LimitedSolutionPool;
import cruncher.Solution;
import cruncher.SolutionPool;

public class SolutionPoolTester {
	SolutionPool pool = null;
	LimitedSolutionPool lpool = null;
	
	@Before
	public void setUp() throws Exception {
		pool = new SolutionPool();
		lpool = new LimitedSolutionPool(5);
	}

	@After
	public void tearDown() throws Exception {
		pool = null;
	}

	@Test
	public void testAddElement() throws Exception{
		for (int i = 1; i < 10; i++)
		{
			pool.addSolution(new Solution(i * 1.0));
			lpool.addSolution(new Solution(i * 1.0));
			//Thread.sleep(20*1000);
			assertTrue(String.format("Min Value is %f", pool.getMin().getObjValue()) ,pool.getMin().getObjValue() == 1.0);
			assertTrue(String.format("Max Value is %f, but added %f", lpool.getMax().getObjValue(), i * 1.0) ,
					lpool.getMax().getObjValue() == i * 1.0); // the size of pool is 5
			assertTrue(String.format("Min Value is %f", lpool.getMin().getObjValue()), lpool.getMin().getObjValue() == 1.0); 
		}
	}
	
	@Test
	public void testRandomElement() throws Exception{
		for (int i = 1; i < 100; i++)
		{
			lpool.addSolution(new Solution(i * 1.0));
			assertTrue(String.format("Pool size is %d ",lpool.size()) ,lpool.getRandom() != null);
		 
		}
	}
}
